import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

/* eslint-disable no-new */
export function createStore() {
  return new Vuex.Store({
    state:{
      num:100
    },
    mutations:{
      count(state,add){
        state.num+=add;
      }
    },
    actions:{
      getCount({commit}){
        return new Promise((resolve,reject)=>{
          setTimeout(()=>{
            commit('count',Math.random()*1000);
            resolve();
          },1000)
        })
      }
    }
  })
}
